package org.codegallery.javagal.concurrent.jcip.c6;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JFrame;

public class InfiniteLoopConsoleTest {
	public static void main(String[] args){
		
		Runnable r1=new Runnable(){
			public void run(){
				long count=0;
				while(true){
					int second=Calendar.getInstance().get(Calendar.SECOND);
					int milliseSecond=Calendar.getInstance().get(Calendar.MILLISECOND);
					
					
					if(milliseSecond % 500==0 && second % 5==0){
						if(count %200 ==0){
							System.out.println(new Date());
						}else{
							count=count+1;
							if(count>200){
								count=0;
//								try {
//									Thread.currentThread().sleep(5000);
//								} catch (InterruptedException e) {
//									// TODO Auto-generated catch block
//									e.printStackTrace();
//								}
							}
							
						}
						
					}
				}	
			}
		};
		Runnable r2=new Runnable(){
			public void run(){
				long count=0;

				while(true){
					int second=Calendar.getInstance().get(Calendar.SECOND);
					int milliseSecond=Calendar.getInstance().get(Calendar.MILLISECOND);
					if(count%500==0){
						if(milliseSecond % 500==0 && second % 5==0){
							System.out.println("r2........");
						}
					}
					count++;
					if(count>500){
						count=0;
//						try {
//							Thread.currentThread().sleep(1000);
//						} catch (InterruptedException e) {
//							// TODO Auto-generated catch block
//							e.printStackTrace();
//						}
						
					}
				}
				
				
			}
		};
		
		new Thread(r1).start();
		new Thread(r2).start();
		
	}	
}
